package com.silence.gankio.mvp.presenter

import com.silence.gankio.bean.GankIoData
import com.silence.gankio.mvp.control.HttpControl
import com.silence.gankio.mvp.control.SplashControl
import com.silence.gankio.mvp.model.SplashModel
import com.silence.gankio.net.GankIoObserver
import com.silence.gankio.sp.SplashSP

class SplashPresenterImpl(view: SplashControl.ISplashView) : BasePresenter<SplashControl.ISplashView>(view),
    SplashControl.ISplashPresenter {

    private val mModel = SplashModel()

    override fun loadImageUrl() {
        mModel.loadImageUrl(object : GankIoObserver<GankIoData>(view as HttpControl.IHttpView) {
            override fun onSuccess(t: GankIoData) {
                if (!SplashSP.INSTANCE.getImageUrl().equals(t.url)) {
                    SplashSP.INSTANCE.setImageUrl(t.url)
                    view?.onLoadImageUrlSuccess(t.url)
                }
            }
        })
    }
}